package edu.codink.common.base;

import java.sql.Timestamp;

import org.hibernate.type.DateType;
import org.hibernate.type.DoubleType;
import org.hibernate.type.FloatType;
import org.hibernate.type.IntegerType;
import org.hibernate.type.LongType;
import org.hibernate.type.SerializableType;
import org.hibernate.type.ShortType;
import org.hibernate.type.StringType;
import org.hibernate.type.TextType;
import org.hibernate.type.TimeType;
import org.hibernate.type.TimestampType;
import org.hibernate.type.Type;

public class StandardBasicTypes
{

	/**
	 * The standard Hibernate type for mapping {@link Short} to JDBC
	 * {@link java.sql.Types#SMALLINT SMALLINT}.
	 * 
	 * @see ShortType
	 */
	public static final ShortType SHORT = new ShortType();

	/**
	 * The standard Hibernate type for mapping {@link Integer} to JDBC
	 * {@link java.sql.Types#INTEGER INTEGER}.
	 * 
	 * @see IntegerType
	 */
	public static final IntegerType INTEGER = new IntegerType();

	/**
	 * The standard Hibernate type for mapping {@link Long} to JDBC
	 * {@link java.sql.Types#BIGINT BIGINT}.
	 * 
	 * @see LongType
	 */
	public static final LongType LONG = new LongType();

	/**
	 * The standard Hibernate type for mapping {@link Float} to JDBC
	 * {@link java.sql.Types#FLOAT FLOAT}.
	 * 
	 * @see FloatType
	 */
	public static final FloatType FLOAT = new FloatType();

	/**
	 * The standard Hibernate type for mapping {@link Double} to JDBC
	 * {@link java.sql.Types#DOUBLE DOUBLE}.
	 * 
	 * @see DoubleType
	 */
	public static final DoubleType DOUBLE = new DoubleType();

	/**
	 * The standard Hibernate type for mapping {@link java.math.BigInteger} to
	 * JDBC {@link java.sql.Types#NUMERIC NUMERIC}.
	 * 
	 * @see BigIntegerType
	 */
	/**
	 * The standard Hibernate type for mapping {@link String} to JDBC
	 * {@link java.sql.Types#VARCHAR VARCHAR}.
	 * 
	 * @see StringType
	 */
	public static final StringType STRING = new StringType();

	/**
	 * The standard Hibernate type for mapping {@link java.util.Date} ({@link java.sql.Time})
	 * to JDBC {@link java.sql.Types#TIME TIME}.
	 * 
	 * @see TimeType
	 */
	public static final TimeType TIME = new TimeType();

	/**
	 * The standard Hibernate type for mapping {@link java.util.Date} ({@link java.sql.Date})
	 * to JDBC {@link java.sql.Types#DATE DATE}.
	 * 
	 * @see TimeType
	 */
	public static final DateType DATE = new DateType();

	/**
	 * The standard Hibernate type for mapping {@link java.util.Date} ({@link java.sql.Timestamp})
	 * to JDBC {@link java.sql.Types#TIMESTAMP TIMESTAMP}.
	 * 
	 * @see TimeType
	 */
	public static final TimestampType TIMESTAMP = new TimestampType();

	/**
	 * The standard Hibernate type for mapping {@link String} to JDBC
	 * {@link java.sql.Types#LONGVARCHAR LONGVARCHAR}. <p/> Similar to a
	 * {@link #MATERIALIZED_CLOB}
	 * 
	 * @see TextType
	 */
	public static final TextType TEXT = new TextType();

	/**
	 * The standard Hibernate type for mapping {@link java.io.Serializable} to
	 * JDBC {@link java.sql.Types#VARBINARY VARBINARY}. <p/> See especially the
	 * discussion wrt {@link ClassLoader} determination on
	 * {@link SerializableType}
	 * 
	 * @see SerializableType
	 */
	public static Type getHibernateType(Object obj)
	{
		if (obj instanceof Integer)
		{
			return StandardBasicTypes.INTEGER;
		} else if (obj instanceof Float)
		{
			return StandardBasicTypes.FLOAT;
		} else if (obj instanceof Timestamp)
		{
			return StandardBasicTypes.TIMESTAMP;
		} else if (obj instanceof Long)
		{
			return StandardBasicTypes.LONG;
		} else
		{
			return StandardBasicTypes.STRING;
		}
	}
}
